<template>
  <div>
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="orderBy" label="排序" width="50">
      </el-table-column>
      <el-table-column prop="fileId" label="缩略图" width="80">
        <template slot-scope="{ row }">
          <img :src="row.httpUrl" class="thumb" @click="handleLook(row)" />
        </template>
      </el-table-column>
      <el-table-column prop="name" label="图片名称"> </el-table-column>
      <el-table-column prop="linkAddr" label="链接地址">
        <template slot-scope="{ row }">
          {{ row.linkAddr || '--' }}
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态" width="80">
        <template slot-scope="{ row }">
          <span v-show="row.status == 1">显示</span>
          <span v-show="row.status != 1">隐藏</span>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" width="180">
      </el-table-column>
      <el-table-column label="操作" width="200">
        <template slot-scope="{ row }">
          <el-button-group>
            <el-button type="success" size="mini" @click="handleLook(row)"
              >预览</el-button
            >
            <el-button type="primary" size="mini" @click="handleEdit(row)"
              >编辑</el-button
            >
            <el-button type="danger" size="mini" @click="handleDelete(row)"
              >删除</el-button
            >
          </el-button-group>
        </template>
      </el-table-column>
      <div slot="empty" class="emptyBg">
        <el-empty :image-size="200"></el-empty>
      </div>
    </el-table>
    <Pagination
      v-show="parseInt(pageObj.count) > 0"
      :total="parseInt(pageObj.count)"
      @change="getList"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
    />
    <ImgPreview />
  </div>
</template>
<script>
import Bus from '@/utils/bus.js'
export default {
  components: {
    ImgPreview: () => import('@/components/resource/imgPreview.vue'),
  },
  data() {
    return {
      listQuery: {
        columnId: '',
        page: 1,
        limit: 10,
      },
      tableData: [],
      pageObj: {},
    }
  },
  props: ['curColumn'],
  watch: {
    'curColumn.id': {
      immediate: true,
      handler() {
        this.getList()
      },
    },
  },
  mounted() {
    this.$bus.$on('refreshPicSourceList', (v) => {
      if (v) {
        Object.assign(this.listQuery, v)
      }
      this.getList()
    })
  },
  beforeDestroy() {
    this.$bus.$off('refreshPicSourceList')
  },
  methods: {
    async getList() {
      this.listQuery.columnId = this.curColumn.id
      let res = await this.$store.dispatch('querySysPicSource', this.listQuery)
      this.tableData = res.data
      this.pageObj = res
    },
    handleEdit(row) {
      this.$bus.$emit('columnImageAdd', row)
    },
    //预览
    handleLook(row) {
      Bus.$emit('showDialogimgPreview', row.httpUrl)
    },
    handleDelete(row) {
      this.deleteTips(() => {
        this.delete(row)
      })
    },
    async delete(row) {
      await this.$store.dispatch('deleteSysPicSource', row)
      this.getList()
    },
  },
}
</script>
<style scoped lang="scss">
.thumb {
  width: auto;
  height: 30px;
  cursor: pointer;
}
</style>